package com.investmenttechnologyservices.datadictionary;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.appengine.api.datastore.Key;
import com.investmenttechnologyservices.model.InstrumentType;
import com.investmenttechnologyservices.model.PositionType;
import com.investmenttechnologyservices.model.PriceFormat;
import com.investmenttechnologyservices.model.StageType;


public class FieldService {
	
	// move to the cache
	static Map<String, EntityMetadata> entityMetadataMap = new HashMap<String, EntityMetadata>();
	static {
		entityMetadataMap.put("trade", new EntityMetadataBuilder().
				setKind("trade").
				setLongId(true).
				
				setField("blockTradeKey", FieldType.KEY).	
				setField("brokerKey", FieldType.KEY).	
				setField("cashAccountKey", FieldType.KEY).	
				setField("counterpartyKey", FieldType.KEY).
				setField("creationTimestamp", FieldType.DATETIME).
				setField("effectiveTimestamp", FieldType.DATETIME).
				setField("expirationTimestamp", FieldType.DATETIME).
				setField("positionType", FieldType.STRING).
				setField("quantityInitial", FieldType.DOUBLE).	
				setField("quantityPrevious", FieldType.DOUBLE).
				setField("quotePrice", FieldType.DOUBLE).
				setField("settlementCurrency", FieldType.STRING).	
				setField("settlementDate", FieldType.DATE).
				setField("stageType", FieldType.STRING).
				setField("symbolKey", FieldType.KEY).
				setField("tags", FieldType.ARRAYSTR).
				setField("tradeDate", FieldType.DATE).	
				setField("tradeId", FieldType.DOUBLE).
				setField("version", FieldType.DOUBLE).
				
				setParent("account").setParentLongId(false).
				
//				setField("price", FieldType.DOUBLE).
//				setField("quantity", FieldType.DOUBLE).
//				setField("symbol", FieldType.STRING).
//				setField("sdate", FieldType.DATE).
				build()
				);

		entityMetadataMap.put("position", new EntityMetadataBuilder().
			setKind("position").
			setLongId(true).
			setField("accountKey", FieldType.KEY).
			setField("symbolKey", FieldType.KEY).
			setField("quantity", FieldType.DOUBLE).
			setField("cost", FieldType.DOUBLE).
			setField("marketValue", FieldType.DOUBLE).
			setField("exposureValue", FieldType.DOUBLE).
			setField("PositionType", FieldType.ENUM).
			setField("StageType", FieldType.ENUM).
			setField("settlementDate", FieldType.DATE).
			setField("tradeKey", FieldType.KEY).
			setField("cashPosition", FieldType.BOOL).
			setField("instrumentType", FieldType.ENUM).
			setField("priceFormat", FieldType.ENUM).
			setField("originalSymbolKey", FieldType.KEY).
			setField("tags", FieldType.ARRAYSTR).
			build()
			);

		entityMetadataMap.put("account", new EntityMetadataBuilder().
				setKind("account").
				setLongId(true).
				setField("name", FieldType.STRING).
				setField("tags", FieldType.STRING).
				setField("firmKey", FieldType.KEY).
				setField("accountId", FieldType.STRING).
				setField("accountPassword", FieldType.STRING).
				setField("bankKey", FieldType.KEY).
				setField("cashAccountKey", FieldType.KEY).
				build()
				);

		entityMetadataMap.put("accountPicker", new EntityMetadataBuilder().
				setKind("account").
				setLongId(true).
				setField("name", FieldType.STRING).
				build()
				);
	}

	public static EntityMetadata getEntityMetadata(String kind) {
		return entityMetadataMap.get(kind);
	}
	
}
